﻿
@{
    ViewData["Title"] = "创建新帖";
}

<style type="text/css">
    .tz_tit {
        height: 30px;
        width: 100%;
        text-align: center;
        height: 50px;
        font-size: 20px;
        color: #666;
        line-height: 50px;
    }
</style>

<div style="width:100%;">
    <div class="tz_tit">创建新帖</div>
    <div>
        <form id="ajaxForm" enctype="multipart/form-data" class="form-horizontal">
            <div class="container-fluid">
                <div class="row form-group">
                    <label class="control-label col-md-1">标题</label>
                    <div class="col-md-11">
                        <input type="text" id="art_title" name="title" class="form-control"/>
                    </div>
                </div>
                <div class="row form-group">
                    <label class="control-label col-md-1">内容</label>
                    <div class="col-md-11">
                        <div id="editor">

                        </div>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-6 col-md-offset-1">
                        <button type="button" class="btn btn-info btn-xs" onclick="SavePost()">保存</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

@section Scripts{
    <script type="text/javascript">
        var E = window.wangEditor
        var editor = new E('#editor')
        // 或者 var editor = new E( document.getElementById('editor') )
        // editor.customConfig.uploadImgShowBase64 = true
        // 将图片大小限制为 3M
        editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024
        editor.customConfig.uploadImgServer = '/upload/user_image'
        // 限制一次最多上传 5 张图片
        editor.customConfig.uploadImgMaxLength = 5
        editor.customConfig.uploadFileName = 'image'
        editor.create();

        function SavePost() {
            if ($("#art_title").val().length === 0) {
                utils.ShowError("请输入标题");
                return;
            }
            if (editor.txt.text().length === 0) {
                utils.ShowError("请输入帖子内容");
                return;
            }

            $("#ajaxForm").ajaxSubmit({
                type: 'post',
                url: '@Url.Action("Save")',
                data: {
                    content: editor.txt.html()
                },  // data是作为额外提交的表单数据
                success: function (e) {
                    console.log(e);
                    if (e.msg == 'ok') {
                        utils.ShowSuccess(e.data, function () {
                            location.href = '@Url.Action("list")';
                        });
                    }
                },
                error: function (e) {
                    utils.ShowError(e.data);
                }
            });
        }
    </script>
}